//
//  HGMineVC.m
//  RedWinMall
//
//  Created by HeDianZhao on 2018/7/27.
//  Copyright © 2018年 HeDianZhao. All rights reserved.
//

#import "HGMineVC.h"
#import "HGMineHeaderView.h"
#import "HGMainCenterVC.h"
#import "HGOrderCenterVC.h"
#import "HGProfileVC.h"
#import "HGRealNameVC.h"

@interface HGMineVC ()<UITableViewDelegate, UITableViewDataSource, HGMineHeaderViewDelegate>

@property (strong, nonatomic) HGMineHeaderView *headerView;

@property (nonatomic,strong)UITableView* tableView;

@property (nonatomic,copy)NSArray *datas;

@end

@implementation HGMineVC

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initSubViews];
    
    _datas = @[@"地址管理",@"积分中心",@"代言中心",@"我要推广",@"我的酒庄",@"抢占商机"];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = YES;
    [self getStatus];
}

#pragma mark - 获取用户基本信息
- (void)getStatus {
    [[LMJRequestManager sharedManager] GET:KBaseURL(@"user/status") parameters:nil completion:^(LMJBaseResponse *response) {
        if (response.responseModel.status == 1) {
            _headerView.user_Name.text = response.responseModel.data[@"nickName"];
            _headerView.user_level.text = response.responseModel.data[@"memberName"];
        }
    }];
}

- (void)initSubViews {
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier = [NSString stringWithFormat:@"cell%ld%ld",indexPath.section,indexPath.row];
    // 通过不同标识创建cell实例
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    // 判断为空进行初始化  --（当拉动页面显示超过主页面内容的时候就会重用之前的cell，而不会再次初始化）
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        
    }
    cell.textLabel.text = _datas[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 4) {
        UILabel *label = [[UILabel alloc] init];
        label.text = @"新装中";
        label.textColor = kColorText;
        label.font = [UIFont systemFontOfSize:12];
        [cell.contentView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(cell.contentView);
            make.right.offset(-15);
        }];
    }
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _datas.count;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *vcNameArr = @[@"QQGoodsAdressVC",@"HGGigIncomeVC",@"HGEstMainVC",@"HGPromoteVC",@"",@"HGBusinessVC"];
    Class class = NSClassFromString(vcNameArr[indexPath.row]);
    [self.navigationController pushViewController:[[class alloc] init] animated:YES];
}

#pragma mark - 订单中心 实名认证
- (void)seletedType:(NSInteger)type {
    
    if (type == 1000) {
        [self.navigationController pushViewController:[HGRealNameVC new] animated:YES];
        return;
    }
    
    HGOrderCenterVC *vc = [[HGOrderCenterVC alloc] init];
    vc.type = type;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 个人中心
- (void)pushMineProfile {
    HGProfileVC *vc = [[HGProfileVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (HGMineHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[HGMineHeaderView alloc] init];
        _headerView.frame = CGRectMake(0, 0, kScreenWidth, 300 + kNavigationHeight/2);
        _headerView.delegate = self;
    }
    return _headerView;
}

- (UITableView *)tableView {
    if (!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 46;
        _tableView.tableFooterView = [UIView new];
        _tableView.tableHeaderView = self.headerView;
        _tableView.backgroundColor = kColorBackground;
        [self.view addSubview:_tableView];
        
        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self.view);
            make.bottom.offset(-kBottomBarHeight);
        }];
    }
    return _tableView;
}

- (BOOL)shouldShowShadowImage {
    return NO;
}

- (BOOL)navigationIsLight {
    return YES;
}

- (UIImage *)navigationBarBackgroundImage {
    return [UIImage new];
}

@end
